/*----------------------------------------------------------------------------
 *      U S B  -  K e r n e l
 *----------------------------------------------------------------------------
 * Name:    usbhw.h
 * Purpose: USB Hardware Layer Definitions
 * Version: V1.20
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express,
 *      implied or statutory, including but not limited to the implied
 *      warranties of fitness for purpose, satisfactory quality and
 *      noninfringement. Keil extends you a royalty-free right to reproduce
 *      and distribute executable files created using this software for use
 *      on NXP Semiconductors LPC microcontroller devices only. Nothing else 
 *      gives you the right to use this software.
 *
 * Copyright (c) 2009 Keil - An ARM Company. All rights reserved.
 *----------------------------------------------------------------------------
 * History:
 *          V1.20 Added USB_ClearEPBuf 
 *          V1.00 Initial Version
 *----------------------------------------------------------------------------*/

#ifndef __USBHW_H__
#define __USBHW_H__


/* USB Error Codes */
#define USB_ERR_PID         0x0001	/* PID Error */
#define USB_ERR_UEPKT       0x0002	/* Unexpected Packet */
#define USB_ERR_DCRC        0x0004	/* Data CRC Error */
#define USB_ERR_TIMOUT      0x0008	/* Bus Time-out Error */
#define USB_ERR_EOP         0x0010	/* End of Packet Error */
#define USB_ERR_B_OVRN      0x0020	/* Buffer Overrun */
#define USB_ERR_BTSTF       0x0040	/* Bit Stuff Error */
#define USB_ERR_TGL         0x0080	/* Toggle Bit Error */

/* USB Hardware Functions */
extern void USBIOClkConfig (void);
extern void USB_Init (void);
extern void USB_Connect (uint32_t con);
extern void USB_Reset (void);
extern void USB_Suspend (void);
extern void USB_Resume (void);
extern void USB_WakeUp (void);
extern void USB_WakeUpCfg (uint32_t cfg);
extern void USB_SetAddress (uint32_t adr);
extern void USB_Configure (uint32_t cfg);
extern void USB_ConfigEP (USB_ENDPOINT_DESCRIPTOR * pEPD);
extern void USB_DirCtrlEP (uint32_t dir);
extern void USB_EnableEP (uint32_t EPNum);
extern void USB_DisableEP (uint32_t EPNum);
extern void USB_ResetEP (uint32_t EPNum);
extern void USB_SetStallEP (uint32_t EPNum);
extern void USB_ClrStallEP (uint32_t EPNum);
extern void USB_ClearEPBuf (uint32_t EPNum);
extern uint32_t USB_ReadEP (uint32_t EPNum, uint8_t * pData);
extern void USB_ReadEP_Terminate (uint32_t EPNum);
extern uint32_t USB_ReadEP_Count (uint32_t EPNum);
extern uint32_t USB_WriteEP (uint32_t EPNum, uint8_t * pData, uint32_t cnt);
extern void USB_WriteEP_Terminate (uint32_t EPNum);
extern void USB_WriteEP_Count (uint32_t EPNum, uint32_t cnt);
extern uint32_t USB_GetFrame (void);
extern void USB_IRQHandler (void);

/*
 *  Read USB Endpoint Data
 *    Parameters:      none
 *    Return Value:    current block data
 *
 *  Use USB_ReadEPCount to switch Endpoint and get block count
 *
 */

static inline uint32_t
USB_ReadEP_Block (void)
{
    return LPC_USB->RxData;
}

/*
 *  Write USB Endpoint Data
 *    Parameters:      data: transmit block data
 *    Return Value:    none
 *
 *  Use USB_ReadEPCount to switch Endpoint and get block count
 *
 */

static inline void
USB_WriteEP_Block (uint32_t data)
{
	LPC_USB->TxData = data;
}

#endif /* __USBHW_H__ */
